Uec3.actionIndexModule = Ext.extend(Ext.app.Module, {
    id: 'action_index',
    objsCollection:new Ext.util.MixedCollection(true),
    getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
    del:function(id){
		var grid=this.getObjByKey("grid");
		Ext.Msg.confirm('信息','确定要删除',function(btn){
		 	if(btn=='yes'){
		 		grid.loadMask.show();
			  	Ext.Ajax.request({
			  	url:Uec3.App.Constants.homeUrl+'/roleTemplate/base!delete.do',
			  	params:{'id':id},
        		success:function(response){
	        		var result=Ext.decode(response.responseText);
	        		if(result.success=='OK'){
	        			grid.getStore().reload();
	        		}else{
	        			Ext.Msg.alert('错误',result.success); 
	        		}
		        	grid.loadMask.hide();
        		},
        		failure:function(){
        			Ext.Msg.alert("信息",'网络问题');
        			grid.loadMask.hide();
        		}
			  	});
		    }
		});
	},
	view:function(id){
		var store=this.getObjByKey("store");
		var record=store.getById(id);
		var desktop =Uec3.App.getDesktop(); 
		desktop.launchWindowByParam("action_operation",{id:id,winId:id}); 
	},
    getPanel:function(params) {
   	var module=this;
	var record=Ext.data.Record.create( [ 
		{
			name : 'id',
			type : 'int',
			mapping : 'id'
		}, {
			name : 'actionName',
			type : 'string',
			mapping : 'actionName'
		}, {
			name : 'methodName',
			type : 'string',
			mapping : 'methodName'
		}, {
			name : 'permissionId',
			type : 'int',
			mapping : 'permissionId'
		}, {
			name : 'permissionName',
			type : 'string',
			mapping : 'permissionName'
		}]);
		var store=new Ext.data.Store( {
			proxy : new Ext.data.HttpProxy( {
				url : Uec3.App.Constants.homeUrl+'/action/base!extList.do'
			}),
			pruneModifiedRecords : true,
			paramNames : {
				start : "start",
				limit : "limit",
				sort : "sort",
				dir : "dir"
			},
			remoteSort:true,
			reader : new Ext.data.JsonReader( {
				totalProperty : 'totalProperty',
				root : 'root'
			}, record),
			listeners:{
			
			}
		});
		module.objsCollection.add("store",store);

	var columnModel = new Ext.grid.ColumnModel( [ 
		new Ext.grid.RowNumberer(), 
		{
		header : '操作',
		width : 75,
		renderer:module.moduleActionRenderer({
			func : "view",
			desc : "操作"
		})
		},
		{
		header : '动作名称',
		width : 150,
		sortable : false,
		align:"right",
		dataIndex : 'actionName'
		},
		{
		header : '方法名称',
		width : 150,
		sortable : false,
		align:"right",
		dataIndex : 'methodName'
		},
		{
		header : '权限名称',
		width : 150,
		sortable : false,
		align:"right",
		dataIndex : 'permissionName'
		}
		]);
				
	var grid=new Ext.grid.GridPanel({
	    cm:columnModel,
		store : store,
		selModel : new Ext.grid.RowSelectionModel( {
			moveEditorOnEnter : true
		}),
		//iconCls : 'icon-grid',
		loadMask : {
			msg : '数据加载中...'
		},
		stripeRows : true,
		autoScroll : true,
		height : 300,
		width : '100%',
		bbar : new Ext.PagingToolbar({
			pageSize : 10,
			store : store,
			displayInfo : true,
			style : 'align:center',
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录"
		}),
		tbar : new Ext.Toolbar(['-', {
			text : '新增',
			iconCls : 'icon-add',
			handler : addNewWindow
		}])	
	});	
	module.objsCollection.add("grid",grid);
	
	function addNewWindow(){
		var desktop =Uec3.App.getDesktop();   
		desktop.launchWindowByParam("action_operation"); 
	}
	var formPanel = new Ext.FormPanel({
		labelAlign : 'right',
		frame : true,
		items : [{
				  height:60,
		          layout:'hbox',
		          border:false,
		          layoutConfig: 
		             {     
		               padding:'5',
					   align:'middle' 
                  },            
		          items:[			             
		             {
		               xtype:'label',
		               text:'浏览action',
		               style: {font:'bold 30px arial,serif'}
		             },{
		                xtype:'spacer',
                        flex:1
		             },{
                        xtype:'textfield',
                        name:'code'
                     },{
                        xtype:'button',
                        text:'查找',                   
                        margins:'0 10',
                        handler:function(){
                        	
                        }
                     },{
                        xtype:'spacer',
                        flex:1
                     }]
			
		},grid]
	});
	
	/*获得操作栏htmlcode*/
	function getHtmlCode(value,metadata,record,rowIndex,store){
/*		var arr=[];
		var res="";
		arr.push("<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\""+"roleTemplate_operation"+"\").view("+record.id+");'>操作</a>");
		if(record.data.status==0){
			arr.push("<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\""+module.id+"\").del("+record.id+");'>删除</a>");
		}
		Ext.each(arr,function(obj){
			res+=obj+" | ";
		});
		res=res.substring(0,res.length-3);*/
		
		return res;
	}
	
	return formPanel;
	},
	initEvent:function(){
		var module=this;
		var win=module.getObjByKey("win");
		win.on('show',function(){
			this.getObjByKey("store").load();
		},module,{single:true});
	},
   createWindow : function(params){
   	  var windowId=this.id;
   	  if(params&&params.winId){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = Uec3.App.getDesktop();   
      var win = desktop.getWindowByUecId(windowId);
      if(!win){ 
      	 var module=this;
         win = desktop.createWindow({
            uecId: windowId,
            width: 800,
            height: 500,
            title:'角色模板列表',
            iconCls: 'acc-icon-saleInvoice',
            shim: false,
            moduleObj:module,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[params=='undefined'?module.getPanel():module.getPanel(params)],
            listeners:{
            	'resize':function(win,width,height){
            		var top=this.items.get(0).items.first();
            		var grid=this.items.get(0).items.last();
            		var winMinWidth=900;
            		var winMinHeight=440;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			grid.setHeight(winMinHeight-110);
            		}else{
            			grid.setHeight(height-110);
            		}
            	}
            }
         });
         module.objsCollection.add("win",win);
         module.initEvent();
      } 
      win.show();
   }
	});
